package com.craftcomputing.client.SearchResult;

import com.craftcomputing.client.Listeners.SearchResultListeners.SearchResultClickListener;
import com.google.gwt.user.client.ui.*;

public class SearchWithin extends Composite {

	/**
	* @wbp.parser.constructor
	*/
	public SearchWithin() {
		makeWidget();
	}
	public SearchWithin(SearchResult searchResult, String entryName) {		
		this.entryName = entryName;
		this.listener = new SearchResultClickListener(searchResult, this.tb);
		makeWidget();
	}
	public void makeWidget(){
		final HorizontalPanel SearchWithinPanel = new HorizontalPanel();
		SearchWithinPanel.setStyleName("gwt-SearchLabel");
		initWidget(SearchWithinPanel);
		SearchWithinPanel.setHeight("30px");
		SearchWithinPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
		SearchWithinPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);

		final VerticalPanel verticalPanel2 = new VerticalPanel();
		SearchWithinPanel.add(verticalPanel2);		
		verticalPanel2.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
		final HorizontalPanel horizontalPanel3 = new HorizontalPanel();
		tb.setName("content");

		horizontalPanel3.add(tb);
		tb.setSize("200px", "23px");
		horizontalPanel3.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
		horizontalPanel3.setCellHorizontalAlignment(tb, HasHorizontalAlignment.ALIGN_LEFT);
		verticalPanel2.add(horizontalPanel3);
		horizontalPanel3.setSpacing(2);
		horizontalPanel3.setHeight("26px");
		
		final Button searchButton = new Button("search");
		if(listener != null)
			searchButton.addClickListener(listener);
		horizontalPanel3.add(searchButton);
		searchButton.setText("search");
		searchButton.setHeight("25px");
	}
	private TextBox tb = new TextBox();
	private String entryName = "Entry Name";
	private ClickListener listener;
	public TextBox getTextBox(){return tb;}
	public String getQuery(){return tb.getText();}
}
